import { createElement, HTMLAttributes, type FC } from 'react';
import classNames from 'classnames';

import { railDefaultProps } from './defaultProps';
import type { RailOptions } from './type';

export interface RailProps extends RailOptions, HTMLAttributes<HTMLDivElement> {}

const Rail: FC<RailProps> = (props) => {
  const { className, position, internal, dividing, attached, close, size, children, forwardedRef, ...railProps } =
    props;

  return createElement(
    'div',
    {
      ref: forwardedRef,
      className: classNames(
        'ui',
        position,
        { internal, dividing, attached },
        size,
        close,
        { close },
        'rail',
        className,
      ),
      ...railProps,
    },
    children,
  );
};

Rail.displayName = 'Rail';
Rail.defaultProps = railDefaultProps;

export default Rail;
